import { execSync } from 'node:child_process'
import express from 'express'

const router = express.Router() //路由模块
const IMG_PATH = `./public/潮点网_59733_720p.mp4` //单前文件的入口为执行文件的入口
router.get('/mp4Togif', (req, res) => {
  console.log('format')
  execSync(`ffmpeg -i ${IMG_PATH} test.gif`, { stdio: 'inherit' })
  res.send({
    val:'test.gif',
  })
})


router.get('/drawtext', (req, res) => {
  console.log('format')//-vf 就是video filter
  execSync(`ffmpeg -i ${IMG_PATH} -vf drawtext=text="amazing":fontsize=30:fontcolor=white:x=10:y=10 test2.mp4`,{stdio:'inherit'})
  res.send({
    val:'test2.mp4',
  })
})


router.get('/startEnd', (req, res) => {
  console.log('format')//-vf 就是video filter
  execSync(`ffmpeg -ss 10 -to 20 -i test.mp4  test3.mp4`,{stdio:'inherit'})
  res.send({
    val:'test3.mp4',
  })
})


router.get('/mp4Tomp3', (req, res) => {
  console.log('format')//-vf 就是video filter
  execSync(`ffmpeg -i test.mp4 test.mp3`,{stdio:'inherit'})
  res.send({
    val:'test.mp3',
  })
})

router.get('/delogo', (req, res) => {
  console.log('format')//-vf 就是video filter
  execSync(`ffmpeg -i  test2.mp4 -vf delogo=w=120:h=30:x=10:y=10 test3.mp4`,{stdio:'inherit'})
  res.send({
    val:'test3.mp4',
  })
})



export default router
